import 'dart:collection';

import 'package:sample2/helper/app_helper.dart';

enum ChatMessageSenderReceiverType { sender, receiver }

enum ChatMessageKind { plainText, picture, video }

class ChatMessage {
  late String? fromNickName = "";
  late String? messageId;
  late String? from;
  late String? toUser;
  late String message;
  late String createTime;
  late String? avatarUrl;
  ChatMessageSenderReceiverType? messageSenderReceiverType =
      ChatMessageSenderReceiverType.receiver;
  ChatMessageKind? messageKind = ChatMessageKind.plainText;

  ChatMessage({
    this.messageId,
    this.toUser,
    this.from,
    this.avatarUrl,
    this.fromNickName,
    this.messageKind,
    required this.message,
    required this.createTime,
    required this.messageSenderReceiverType,
  });

  ChatMessage.fromJsonMap(Map jsonMap) {
    message = jsonMap["message"];
    toUser = jsonMap["to"];
    from = jsonMap["from"];
    fromNickName = jsonMap["nickname"];
    avatarUrl = jsonMap["avatar"];
    createTime = jsonMap["createTime"];
    messageId = jsonMap["msgId"];
  }

  Map toParameter() {
    return HashMap.from({
      "fromNickName": fromNickName,
      "createTime": createTime,
      "messageId": messageId,
      "avatarUrl": avatarUrl,
      "message": message,
      "to": toUser,
      "from": from,
    });
  }

  String getAvatarUrl() {
    //TODO: replace the value here with dot env file
    return avatarUrl ??
        "${AppHelper.shared.getBkDomainName()}/images/2022-12-07T01:54:19.821Z_labi.jpg";
  }
}
